import LCData from "../GMDWeakNetGameBase/LCData";
import FB from "./FB";
import MsgBox from "../GMDBase/MsgBox";


let g_BotFailed = false//本次游戏过程中是否失败过
let g_BotUserCancel = false//本次游戏过程中用户是否取消过
//canSubscribeBotAsync()
//subscribeBotAsync()
//instant_games.bot.subscription_type("OPT_IN_DEV"|"OPT_IN_PUBLIC")
export default class BotMgr
{
    //当前是否需要SubscribeBot
    public static get NeedSubscribeBot()
    {
        if(g_BotFailed||g_BotUserCancel) return false

        return LCData.GetNumber(LCData.ParamName.SHORTCUTS_ST) == 0
    }

    public static SubscribeBotAsyncNoMsg()
    {
        if(!FB.InFB) return
        if(!BotMgr.NeedSubscribeBot) return

        FBInstant.player.canSubscribeBotAsync().then(
            can_subscribe => {
                if(can_subscribe)
                {
                    FBInstant.player.subscribeBotAsync().then(
                        ()=>{
                            LCData.Set(LCData.ParamName.SHORTCUTS_ST,"1")
                            console.log("bot成功")
                            FB.logEvent("subscribe_bot_success",1,{})
                        }
                      ).catch(
                        (e)=> {
                             // Handle subscription failure
                             g_BotFailed = true
                             console.log("bot失败",e)
                             FB.logEvent("subscribe_bot_failed",1,{})
                        }
                      );

                }else
                {
                    g_BotFailed = true
                    console.log("can_subscribe is false")
                    FB.logEvent("subscribe_bot_failed",1,{})
                }
            }
        ).catch((e)=>{
            g_BotFailed = true
            console.log("canSubscribeBotAsync catch!")
        })
    }

    //执行SubscribeBot
    public static SubscribeBotAsync(msg:string)
    {
        /*
        if(!FB.InFB) return
        if(!BotMgr.NeedSubscribeBot) return

        MsgBox.ShowOKCancel("",msg,"Yes","No",
            ()=>{
                console.log("用户选择yes")
                BotMgr.SubscribeBotAsyncNoMsg()
            },
            ()=>{
                g_BotUserCancel = true
            }
        )
        */
    }
 
}